/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.liquidByte.trafficMustang.server.webService;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import org.liquidByte.trafficMustang.server.dataModel.Avaliacao;
import org.liquidByte.trafficMustang.server.services.AvaliacaoService;
import org.liquidByte.trafficMustang.server.services.ConverterService;
import org.liquidByte.trafficMustang.server.webService.base.WebService;
import org.liquidByte.trafficMustang.server.webService.dto.AvaliacaoDTO;

/**
 * REST Web Service
 *
 * @author Alexandre
 */
@Stateless
@Path("avaliacao")
public class AvaliacaoWebService extends WebService {

    @EJB
    private AvaliacaoService avaliacaoService;
    @EJB
    private ConverterService converter;

    @POST
    @Produces("application/json")
    @Consumes("application/json")
    @Path("registrar")
    public String registrar(String data) {
        try {
            AvaliacaoDTO dto = this.toObject(data, AvaliacaoDTO.class);
            Avaliacao aval = this.converter.getAvaliacaoDto().convert(dto);
            this.avaliacaoService.registrar(aval);
            return this.success();
        } catch (Exception e) {
            return this.error(e);
        }
    }
}

